<template>
	<div class="container">
		<uv-navbar bgColor='transparent' :placeholder='true' :fixed='false'>
			<template v-slot:left>
				<view class="title"></view>
			</template>
			<template v-slot:center>
				<view class="title">脑立扬</view>
			</template>
		</uv-navbar>

		<div class="head_box">
			<img class="bgi" src="/static/1.png" alt="">
			<div class="search" @click='navTo("/pages/search/search")'>
				<image src="/static/search.png" class="icon" alt=""/>
				<text class="text">搜索科普、资讯</text>
			</div>
		</div>

		<div class="content">
			<!-- swiepr -->
			<div class="swiper">
				<uv-swiper class="uv_swiper" height="400rpx" keyName="image" @click='swiperClick'  :list="banner" @change="e => current1 = e.current" :autoplay="false" :circular='true'>
				</uv-swiper>
				<view class="indicator">
					<view class="indicator__dot" v-for="(item, index) in banner" :key="index"
						:class="[index === current1 && 'indicator_active']"></view>
				</view>
			</div>
			<!-- menu -->
			<div class="menus">
				<div class="item" v-for="(item,index) in menus" :key='index' @click='toMenu(item)'>
					<image class="icon" :src="item.image" mode=""></image>
					<div class="name">{{item.title}}</div>
				</div>
			</div>
			<!-- title -->
			<div class="tit_box">
				<div class="name">健康资讯</div>
				<div class="more" @click='toMore'>更多》</div>
			</div>
			<!-- list -->
			<div class="list_box">
				<div class="item" @click='toDetail(item.id)' v-for="(item,index) in listData.list" :key="index">
					<image class="pic"  :src="item.image" mode=""></image>
					<div class="desc">{{item.title}}</div>
				</div>
				<!-- <div class="more_bar" @click='lookMore'>查看更多</div> -->
			</div>
		</div>



	</div>
</template>

<script>
	import { getBanner,getDisease,getIndexnews,getDaoLan } from '@/network/api.js'
	import { baseURL } from '@/network/config.js'
	export default {
		data() {
			return {
				current1: 0,
				banner: [
				
				],
				menus:[],
				listData:{
					list:[],
					total:0
				},
				query:{ page:1,limit:10},

			}
		},
		onLoad() {
			this.getBannerList()
			this.getDiseaseList()
			this.getIndexnewsList(this.query)
		},
		onShareAppMessage(){
			
		},
		onShareTimeline(){
			
		},
		methods: {
			navTo(path){uni.navigateTo({url: path});},
			async getBannerList(){
				const {data} = await getBanner()
				this.banner = data.map(i=>({...i, image:`${baseURL}${i.image}`}))
			},
			async getDiseaseList(){
				const {data} = await getDaoLan()
				this.menus = data.map(i=>({...i, image:`${baseURL}${i.image}`}))
			},
			async getIndexnewsList(query){
				const {data} = await getIndexnews(query)
				console.log('res:',data)
				const list = data.list.map(i=>({...i, image:`${baseURL}${i.image}`}))
				data.list = list
				if(list.length==0){
					uni.showToast({title: '没有更多了',duration: 2000,icon:'none'});
					this.query.page --
				}
				this.listData.list = [...this.listData.list,...data.list].splice(0,8)
			},
			lookMore(){
				this.query.page ++
				this.getIndexnewsList(this.query)
			},
			swiperClick(index){
				const item = this.banner[index]
				console.log('item:',item)
				this.toDetail(item.id)
			},
			toDetail(id){
				uni.navigateTo({
					url:`/pages/chidai_detail/chidai_detail?id=${id}`
				})
			},
			toMenu(item){
				console.log('////:',item)
				if(item.type == 1){
					uni.navigateTo({
						url:`/pages/chi_dai_list/chi_dai_list?id=${item.dataId}&title=${item.title}`
					})
				}
				if(item.type == 2){
					uni.navigateTo({
						url:`/pages/news/news?id=${item.id}&title=${item.title}`
					})
				}
				if(item.type == 3){
					if(item.title=='产品介绍'){
						uni.navigateTo({
							url:`/pages/empty/empty`
						})
						return
					}
					uni.switchTab({
						url:item.dataId
					})
				}
			},
			toMore(){
				// uni.navigateTo({url: `/pages/search_result/search_result?keyword=${''}`})
				uni.switchTab({url: `/pages/copue/copue`})
			}
		}
	}
</script>

<style lang="less">
	.title {
		font-size: 32rpx;
		font-weight: bold;
		color: #363636;
	}

	.head_box {
		.bgi {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			width: 100%;
			height: 460rpx;
			z-index: -99;
		}
	}

	.search {
		height: 70rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		margin: 0 25rpx;
		display: flex;
		align-items: center;
		padding: 0 30rpx;
		margin-top: 10rpx;
		.icon {
			width: 35rpx;
			height: 35rpx;
			margin-right: 10rpx;
		}

		.text {
			font-size: 25rpx;
			font-weight: 400;
			color: #898989;
		}
	}
	.content{
		padding: 25rpx;
	}
	.swiper {
		.indicator{
			display: flex;
			justify-content: center;
			margin: 15rpx 0;
			.indicator__dot{
				width: 18rpx;
				height: 18rpx;
				background: #E7E7E7;
				border-radius: 50%;
				margin:0 6rpx;
			}
			.indicator_active{
				background: #4E6FD9;
			}
		}
	}
	.menus{
		display: flex;
		flex-wrap: wrap;
		.item{
			display: flex;
			flex-direction: column;
			align-items: center;
			margin-top: 32rpx;
			width: 33%;
			.icon{
				width: 128rpx;
				height: 128rpx;
			}
			.name{
				font-size: 24rpx;
				font-weight: 400;
				color: #3E3E3E;
				margin-top: 15rpx;
			}
		}
	}
	.tit_box{
		height: 80rpx;
		border-radius: 10rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 20rpx;
		margin-top: 50rpx;
		background: url(/static/12.png) no-repeat center/100% 100%;
		.name{
			font-size: 32rpx;
			font-weight: bold;
			color: #000000;
		}
		.more{
			font-size: 24rpx;
			font-weight: 400;
			color: #373737;
		}
	}
	.list_box{
		.item{
			display: flex;
			padding: 33rpx 0;
			border-bottom:1px solid #EAEAEA;
			.pic{
				width: 340rpx;
				height: 210rpx;
				background: #F2F2F2;
				border-radius: 10rpx;
				flex-shrink: 0;
			}
			.desc{
				font-size: 28rpx;
				font-weight: 400;
				color: #444444;
				line-height: 50rpx;
				flex:1;
				margin: 18rpx 0 0 25rpx;
			}
		}
		.more_bar{
			font-size: 24rpx;
			font-weight: 400;
			color: #BDBDBD;
			padding: 30rpx 0;
			text-align: center;
		}
	}
</style>